var Webapp = function() {

	this.init = function() {

		// 模拟上传excel
		$("#uploadEventBtn").unbind("click").bind("click", function() {
			$("#uploadEventFile").click();
		});
		$("#uploadEventFile").bind("change", function() {
			$("#uploadEventPath").attr("value", $("#uploadEventFile").val());
		});

	};
	// 点击上传按钮
	this.uploadBtn = function() {
		var uploadEventFile = $("#uploadEventFile").val();

		if (uploadEventFile == '') {
			alert("请选择excel,再上传");
		} else if (uploadEventFile.lastIndexOf(".xls") < 0) {// 可判断以.xls和.xlsx结尾的excel
			alert("只能上传Excel文件");
		} else {
			var url = 'daoru/upload/';
			var formData = new FormData($('form')[0]);
			webapp.sendAjaxRequest(url, 'POST', formData);
		}
	};

	this.sendAjaxRequest = function(url, type, data) {
		$.ajax({
			url : url,
			type : type,
			data : data,
			success : function(result) {
				if (result == 1) {
					webapp.cha();
					alert("上传成功");

				} else if (result == 0) {
					alert("上传失败");
				}

			},
			error : function() {
				alert("excel上传失败");
			},
			cache : false,
			contentType : false,
			processData : false
		});
	};

	this.cha = function() {
		$.ajax({
			url : 'apply/findsuoajax/',
			type : 'POST',
			data:{
				
			},
			success : function(data) {
				$("#baseTable tbody").empty();
				$("#show").show();
				var html = "";
				if (data != null) {
					for (var j = 0; j < data.length; j++) {
						var l = data[j];
						html += "<tr>";
						html += "<td>" + l.id + "</td>";
						html += "<td>" + l.sqid + "</td>";
						html += "<td>" + l.gzdm + "</td>";
						html += "<td>" + l.xm + "</td>";
						html += "<td>" + l.je + "</td>";
						html += "<td>" + l.lx + "</td>";
						html += "<td>" + l.bz + "</td>";
						html += "<td>" + l.yearAndMonth + "</td>";
						html += "</tr>";
					}
					$("#baseTable tbody").append(html);
				}
			}
		});
	};
}


function printById(id) {  
	html2canvas(document.getElementById(id), {  
        allowTaint : true,  
        taintTest : false,  
        onrendered : function(canvas) {  
            canvas.id = "mycanvas";  
            //document.body.appendChild(canvas);  
            //生成base64图片数据  
            var dataUrl = canvas.toDataURL();  
            var newImg = document.createElement("img");  
            newImg.src = dataUrl;  
            /* document.body.appendChild(newImg);  */  
            /* window.open(newImg.src); */  
            var printWindow = window.open(newImg.src);  
                // printWindow.document.write();   
                 printWindow.document.write('<img src="'+newImg.src+'" />')  
                 printWindow.print();  
    }  
});  
} 
 

var webapp;
$(function() {
	webapp = new Webapp();
	webapp.init();
});
